//package com.franklin.ideaplugin.easytesting.ui.history;
//
//import cn.hutool.core.collection.CollectionUtil;
//import com.franklin.ideaplugin.api.ui.AbstractComponent;
//import com.franklin.ideaplugin.api.utils.ProjectUtils;
//import com.franklin.ideaplugin.api.utils.SwingUtils;
//import com.franklin.ideaplugin.easytesting.cache.IEasyTestingCache;
//import com.franklin.ideaplugin.easytesting.entity.ExecuteResult;
//import com.franklin.ideaplugin.easytesting.ui.execute.ExecuteMethodFormNew;
//import com.franklin.ideaplugin.easytesting.ui.ExecuteMethodResultForm;
//import com.franklin.ideaplugin.easytesting.ui.Sizes;
//import com.intellij.psi.PsiMethod;
//
//import javax.swing.*;
//import java.awt.*;
//import java.util.Collections;
//import java.util.List;
//import java.util.Map;
//import java.util.Objects;
//
///**
// * @author Ye Junhui
// * @since 2023/6/21 21:39
// */
//public class ExecuteHistoryForm extends AbstractComponent {
//    private JPanel panel1;
//    private JPanel timePanel;
//    private JPanel paramPanel;
//    private JPanel resultPanel;
//    private JPanel mainPanel;
//    private JPanel middlePanel;
//    private JPanel rightPanel;
//
//    private JComponent parent;
//
//    private ExecuteMethodFormNew executeMethodFormNew;
//    private ExecuteMethodResultForm executeMethodResultForm;
//
//    private final PsiMethod psiMethod;
//
//    public ExecuteHistoryForm(PsiMethod psiMethod) {
//        this.psiMethod = psiMethod;
//    }
//
//    public void setParent(JComponent parent) {
//        this.parent = parent;
//    }
//
//    public void init(){
//        //参数面板
//        IEasyTestingCache easyTestingCache = IEasyTestingCache.getInstance(ProjectUtils.getCurrProject());
//        List<ExecuteResult> executeResultList = easyTestingCache.getExecuteResultList(psiMethod);
//        if (CollectionUtil.isEmpty(executeResultList)){
//            this.refresh(null);
//        }else {
//            this.refresh(executeResultList.get(0));
//        }
//    }
//
//    /**
//     * 刷新面板
//     * @param executeResult
//     */
//    public void refresh(ExecuteResult executeResult){
//        this.refreshTimePanel(executeResult);
//        this.refreshParamPanel(executeResult);
//        this.refreshResultPanel(executeResult);
//        this.parent.validate();
//    }
//
//    private void refreshTimePanel(ExecuteResult executeResult){
//        HistoryTree historyTree = new HistoryTree(psiMethod, this);
//        this.timePanel.removeAll();
//        this.timePanel.setLayout(SwingUtils.createLayoutManager(1,1));
//        this.addCell(this.timePanel, historyTree.getMainPanel(), 0,0, Sizes.ExecuteHistoryFormSize.TIME_SIZE);
//    }
//
//    public void resize(Dimension parentSize){
//        int width = (int) ((parentSize.width - 250) / 2.0);
//        Dimension dimension = new Dimension(width -50 , parentSize.height - 50);
//        Dimension dimensionParam = new Dimension(width - 50, parentSize.height + 50);
//        this.paramPanel.setSize(dimensionParam);
//        if (Objects.nonNull(executeMethodFormNew)){
//            this.paramPanel.removeAll();
//            executeMethodFormNew.getMainPanel().setSize(dimensionParam);
//            this.addCell(this.paramPanel,executeMethodFormNew.getMainPanel(),0,0,dimensionParam);
//        }
//        this.resultPanel.setSize(dimension);
//        if (Objects.nonNull(executeMethodResultForm)){
//            this.resultPanel.removeAll();
//            executeMethodResultForm.getMainPanel().setSize(dimension);
//            executeMethodResultForm.resize(dimension);
//            this.addCell(this.resultPanel,executeMethodResultForm.getMainPanel(),0,0,dimension);
//        }
//    }
//
//    /**
//     * 刷新参数面板
//     * @param executeResult
//     */
//    private void refreshParamPanel(ExecuteResult executeResult){
//        Map<String,Object> paramMap = Collections.emptyMap();
//        if (Objects.nonNull(executeResult)){
//            paramMap = executeResult.getParamMap();
//        }
//
//        executeMethodFormNew = new ExecuteMethodFormNew(
//                psiMethod,
//                paramMap,
//                this::refresh
//        );
//        this.paramPanel.removeAll();
//        this.paramPanel.setLayout(SwingUtils.createLayoutManager(1,1));
//        this.addCell(this.paramPanel, executeMethodFormNew.getMainPanel(), 0,0, Sizes.ExecuteHistoryFormSize.PARAM_SIZE);
//    }
//
//    /**
//     * 刷新参数面板
//     * @param executeResult
//     */
//    private void refreshResultPanel(ExecuteResult executeResult){
//        if (Objects.isNull(executeResult)){
//            return;
//        }
//
//        executeMethodResultForm = new ExecuteMethodResultForm(psiMethod, executeResult.getEtRsp());
//        this.resultPanel.removeAll();
//        this.resultPanel.setLayout(SwingUtils.createLayoutManager(1,1));
//        this.addCell(this.resultPanel, executeMethodResultForm.getMainPanel(), 0,0, Sizes.ExecuteHistoryFormSize.RESULT_SIZE);
//    }
//
//    @Override
//    public JComponent getMainPanel() {
//        return mainPanel;
//    }
//}
